/*
 * Powered By 
 * Since 2010 - 2016
 */

package com.rf.sys.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rf.sys.dao.UserRoleMapper;
import com.rf.sys.dao.SqlAdapterMapper;
import com.rf.sys.model.UserRole;
import com.rf.sys.model.UserRoleExample;
import com.rf.sys.service.UserRoleService;
import com.rf.sys.utils.PageUtils;
import com.rf.sys.utils.UuidUtil;

@Service("userRoleService")
public class UserRoleServiceImpl implements UserRoleService {
	
	@Autowired
   	private SqlAdapterMapper sqlAdapterMapper;//注入dao
   	@Autowired
   	private UserRoleMapper userRoleMapper;//注入dao

   	/**
	 * 根据id获取数据
	 * @param userRoleId
	 * @return UserRole
	 */
   	@Override
	public UserRole getUserRoleByID(String id) throws Exception{
		// TODO Auto-generated method stub
		return userRoleMapper.selectByPrimaryKey(id);
	}
	
	/**
	 * 根据UserRole获取数据
	 * @param UserRole
	 * @return List<UserRole>
	 */
	@Override
	public List<UserRole> getUserRole(UserRole userRole) throws Exception{
		// TODO Auto-generated method stub
		UserRoleExample example = new UserRoleExample();
		List<UserRole> list = userRoleMapper.selectByExample(example);
		return list;
	}
	
	/**
	 * 获取所有数据
	 * @param 
	 * @return List<UserRole>
	 */
	@Override
	public List<UserRole> getUserRole() throws Exception{
		// TODO Auto-generated method stub
		UserRoleExample example = new UserRoleExample();
		return userRoleMapper.selectByExample(example);
	}
   	
	/**
	 * 保存信息
	 * @param UserRole
	 * @return
	 */
	@Override
	public void addUserRole(UserRole userRole) throws Exception{
		// TODO Auto-generated method stub
		userRole.setId(UuidUtil.get32UUID());
		userRoleMapper.insert(userRole);
	}

	/**
	 * 修改数据
	 * @param UserRole
	 * @param
	 */
	@Override
	public void updateUserRole(UserRole userRole) throws Exception{
		// TODO Auto-generated method stub
		userRoleMapper.updateByPrimaryKeySelective(userRole);
	}
	
	/**
	 * 删除数据
	 * @param userRoleId
	 * @param
	 */
	@Override
	public void deleteUserRole(String id) throws Exception{
		// TODO Auto-generated method stub
		userRoleMapper.deleteByPrimaryKey(id);
	}

	/**
	 * 获取数据分页
	 * @param UserRole
	 * @param limit
	 * @param offset
	 * @return Map
	 */
	@Override
	public Map getUserRolePage(UserRole userRole,PageUtils pageUtils) throws Exception{
		UserRoleExample example = new UserRoleExample();
		com.rf.sys.model.UserRoleExample.Criteria criteria= example.createCriteria();
		
		//获取第page页，每页共rows条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		//下一条执行语句，即为要被转换的语句
		List<UserRole> list = userRoleMapper.selectByExample(example);
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}
}

